<?php
header("Content-type: text/html; charset=utf-8");
ini_set('display_errors', 1);
set_time_limit(0);
include_once dirname(dirname(__FILE__)) . '/mgtv_init.php';
//include_once dirname(dirname(dirname(__FILE__))) . '/nn_logic/message/message_group.class.php';
//include_once dirname(dirname(dirname(__FILE__))) . '/nn_logic/message/nl_message.class.php';
//include_once dirname(dirname(dirname(__FILE__))) . '/nn_logic/message/message_group_list.class.php';
class timer_execute extends nn_timer
{
    public function action($params = null)
    {
        $this->msg('开始执行...');
        do_timer_action();
        $this->msg('执行结束...');
    }
}
$arr_files = pathinfo(__FILE__);
$file_name = $arr_files['filename'];
$timer_execute = new timer_execute($file_name, ORG_ID,__FILE__);
$timer_execute->run();

function do_timer_action()
{
    $queue_task_model = new queue_task_model();
    $sp_list = sp_model::get_sp_list();
    if (is_array($sp_list) && $sp_list != null)
    {
        foreach ($sp_list as $sp_info)
        {
            $sp_config = sp_model::get_sp_config($sp_info['nns_id']);
            if(isset($sp_config['disabled_epg'])&&(int)$sp_config['disabled_epg']===1){
                i_echo('close epg');
            }else{
                $sql = $queue_task_model->get_epg_sql($sp_info['nns_id'], 'index');
                echo $sql;

                if($sql!==null){
                    $db = nn_get_db(NL_DB_READ);
                    $c2_list = nl_db_get_all($sql, $db);
//                    var_dump($c2_list);die;
                    if(is_array($c2_list)&&count($c2_list)>0){
                        foreach($c2_list as $c2_info){
                            import_model::import_clip($c2_info['nns_id']);
                        }
                    }
                }
            }
        }
    }
}
